package com.qfedu.user.controller;

import com.qfedu.common.R;
import com.qfedu.user.pojo.User;
import com.qfedu.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class LogInOutController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public R<Integer> login(@RequestBody User user, HttpSession session){
        return R.ok(userService.login(user, session));
    }

    @PostMapping("/logout")
    public R<Boolean> logout(HttpSession session){
        session.invalidate(); //使得session失效
        return R.ok(true);
    }
}
